package com.hengpeng.itfin.job.draw;

import java.util.Map;
import java.util.Set;

import com.hengpeng.common.cis.ComponentContextLoader;
import com.hengpeng.common.scheduling.AbstractJob;
import com.hengpeng.common.scheduling.ScheduleConfig;
import com.hengpeng.itfin.domain.draw.common.Constants;
import com.hengpeng.itfin.domain.draw.common.FileZipHelper;
import com.hengpeng.itfin.service.ServiceFactory;

/**
 * <pre>
 * 解析提款结果文件任务
 * </pre>
 * @author shanguogang
 * @version 1.0, 2015-8-12
 */
public class ParseZipJob extends AbstractJob
{

	@Override
	public void exec(boolean isTimeout, ScheduleConfig config)
	{
		ServiceFactory serviceFactory = ComponentContextLoader.getBean(ServiceFactory.class);
		serviceFactory.getDrawFileService().requireNeverDealDrawFile();
	}

	public static void testParseZip(String file)
	{
		try
		{
			log.info("开始分析 [" + file + "]");
			Map<String, byte[]> fileMap = FileZipHelper.unZip(file, "gbk");
			log.info("分析 [" + file + "] 完成.");

			Set<String> keySet = fileMap.keySet();
			String fileNames[] = new String[keySet.size()];
			keySet.toArray(fileNames);
			for (int i = 0; i < fileNames.length; i++)
			{
				if (fileNames[i].indexOf(Constants.POSTFIX_CSV) > 0
						&& fileNames[i].indexOf(Constants.ALIPAY__RESULT_CSV) == -1)
				{// deal with

					log.info("开始分析[" + file + "]中的子文件[" + fileNames[i] + "] ");
					byte[] b = fileMap.get(fileNames[i]);
					String fileContent = new String(b, 0, b.length);
					log.info("内容：" + fileContent);
				}
			}
		}
		catch (Exception e)
		{
			log.info("解析并处理提款结果文件时出现异常");
			e.printStackTrace();
		}

	}

	public static void main(String args[])
	{
		testParseZip("D:\\ALIPAY_PAY_RESULT_20150812120000209_20150812164812.zip");
	}
}
